package EmploymentLengthAV;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public  class EmploymentLengthAVReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
    public void reduce(Text key,Iterable<IntWritable> values,Context context) throws IOException, InterruptedException{
        int num=0;
        int count=0;
        for(IntWritable val:values){
            //每个元素求和num
            num+=val.get();
            //统计元素的次数count
            count++;
        }
        //统计次数
        int avg=num/count;
        context.write(key,new IntWritable(avg));
    }
}